package com.leetcode.LC_MED;

import java.util.Arrays;

public class LC75 {

    public void sortColors(int[] nums) {
        //遇到0放最前面，遇到2放到最后面
        if (nums.length == 1) {
            return;
        }
        int a = 0, b = nums.length - 1;
        int i = 0, j = 0, tmp;
        for (int k = 0; k <= b - j; k++) {
            if (nums[k] == 0 && k > i) {
                tmp = nums[k];
                nums[k] = nums[i];
                nums[i] = tmp;
                i++;
                k--;
            }else if (nums[k] == 2 && b - j > k){
                tmp = nums[k];
                nums[k] = nums[b - j];
                nums[b - j] = tmp;
                j++;
                k--;
            }
        }
    }

    public static void main(String[] args) {
        new LC75().sortColors(new int[]{2, 0, 2, 1, 1, 0});
    }
}
